package com.example.pmxt.modules.dict;

import com.example.pmxt.common.ReturnResult;
import com.example.pmxt.domain.Dict;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

//@Api
@RestController
@RequestMapping("/dicts")
public class DictController {

    private DictService dictService;

    @Autowired
    public DictController(DictService dictService) {
        this.dictService = dictService;
    }

    @PostMapping("/add")
    public ReturnResult insert( @RequestBody @Validated Dict dict) {
        return ReturnResult.buildSuccessResult(dictService.save(dict));
    }

    @GetMapping("/getDictAll")
    public ReturnResult selectAll(){
        return ReturnResult.buildSuccessResult(dictService.list());
    }

    @GetMapping("/{id}")
    public ReturnResult getById(@PathVariable Integer id){
        return ReturnResult.buildSuccessResult(dictService.getById(id));
    }

    @PutMapping("/update")
    public ReturnResult updateById(@Validated @RequestBody Dict dict ) {
        return ReturnResult.buildSuccessResult(dictService.updateById(dict));
    }

    @DeleteMapping("/{id}")
    public ReturnResult deleteById(@PathVariable Integer id) {
        return ReturnResult.buildSuccessResult(dictService.removeById(id));
    }

}